package com.oracle.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oracle.compents.PageResult;
import com.oracle.mapper.PhReservationMapper;
import com.oracle.pojo.PhReservation;
import com.oracle.pojo.PhReservationExample;
import com.oracle.pojo.PhReservationExample.Criteria;
import com.oracle.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现层
 * @author Administrator
 *
 */
@Service
public class ReservationServiceImpl implements ReservationService {

	@Autowired
	private PhReservationMapper reservationMapper;

	/**
	 * 查询全部
	 */
	@Override
	public List<PhReservation> findAll() {
		return reservationMapper.selecPhyExample(null);
	}

	/**
	 * 按分页查询
	 */
	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		Page<PhReservation> page=   (Page<PhReservation>) reservationMapper.selecPhyExample(null);
		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 增加
	 */
	@Override
	public void add(PhReservation reservation) {
		reservationMapper.insert(reservation);
	}


	/**
	 * 修改
	 */
	@Override
	public void update(PhReservation reservation){
		reservationMapper.updateByPrimaryKey(reservation);
	}

	/**
	 * 根据ID获取实体
	 * @param id
	 * @return
	 */
	@Override
	public PhReservation findOne(Long id){
		return reservationMapper.selecPhyPrimaryKey(id);
	}

	/**
	 * 批量删除
	 */
	@Override
	public void delete(Long[] ids) {
		for(Long id:ids){
			reservationMapper.deleteByPrimaryKey(id);
		}
	}


		@Override
	public PageResult findPage(PhReservation reservation, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);

		PhReservationExample example=new PhReservationExample();
		Criteria criteria = example.createCriteria();

		if(reservation!=null){
						if(reservation.getUname()!=null && reservation.getUname().length()>0){
				criteria.andUnameLike("%"+reservation.getUname()+"%");
			}			if(reservation.getShoplist()!=null && reservation.getShoplist().length()>0){
				criteria.andShoplistLike("%"+reservation.getShoplist()+"%");
			}			if(reservation.getPetcolor()!=null && reservation.getPetcolor().length()>0){
				criteria.andPetcolorLike("%"+reservation.getPetcolor()+"%");
			}			if(reservation.getReservationtime()!=null && reservation.getReservationtime().length()>0){
				criteria.andReservationtimeLike("%"+reservation.getReservationtime()+"%");
			}			if(reservation.getSevertype()!=null && reservation.getSevertype().length()>0){
				criteria.andSevertypeLike("%"+reservation.getSevertype()+"%");
			}			if(reservation.getRemark()!=null && reservation.getRemark().length()>0){
				criteria.andRemarkLike("%"+reservation.getRemark()+"%");
			}
		}

		Page<PhReservation> page= (Page<PhReservation>)reservationMapper.selecPhyExample(example);
		return new PageResult(page.getTotal(), page.getResult());
	}

}
